<!DOCTYPE html>
<html lang="en">
<head>
    <title>电子缴费</title>
    <#include "../inc/header.ftl"/>
</head>

<body class="no-skin">

<div class="main-container ace-save-state" id="main-container">

    <div class="main-content">
        <div class="main-content-inner">

            <div class="page-content">
                <div class="row">
                    <div id="grid-main-data" class="col-xs-12">
                        <table id="MainGrid" style="min-height: 500px"></table>
                        <div id="toolbar">
                            <div style="padding:8px">
                                缴费书号：<input id="billnum" class="easyui-textbox" style="width:140px">&emsp;
                                交易流水号：<input id="bankaffirmfind" class="easyui-textbox" style="width:140px">&emsp;
                                收款账户：<input id="bankid">&emsp;
                                收款时间：<input id="paybankdt" class="easyui-datebox" style="width:140px">&emsp;
                                <a href="#" onclick="javascript:searchInfo()" class="easyui-linkbutton"
                                   iconCls="icon-search">查 询</a>
                            </div>
                            <div style="padding:8px 8px 4px">
                                <a href="#" class="easyui-linkbutton" iconCls="icon-send"
                                   onclick="javascript:sendInfo(1)">发送</a>
                                <a href="#" class="easyui-linkbutton" iconCls="icon-back"
                                   onclick="javascript:sendInfo(2)">冲销</a>
                            </div>
                        </div>
                    </div>
                </div><!-- /.row -->
            </div><!-- /.page-content -->
            <#--修改-->
            <div id="SendBox-add" class="ui-dialog-content hide">
                <div style="padding:8px">
                    复核用户编码：<input id="usercode" class="easyui-textbox" style="width:110px" data-options="required:true" >&emsp;
                    复核用户密码：<input id="userpwd" class="easyui-passwordbox" style="width:110px" data-options="required:true" >&emsp;
                    <input id="biaoshi" hidden>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-redo" onclick="javascript:pageSendInfo()"><span id="sendClean"></span></a>
                </div>
                <table id="SendMainGrid"></table>
            </div>
        </div>
    </div><!-- /.main-content -->
</div><!-- /.main-container -->

<!-- basic scripts -->
<#include "../inc/basicjs.ftl"/>

<!-- inline scripts related to this page -->
<script type="text/javascript">

    jQuery(function ($) {
        $('#MainGrid').datagrid({
            url:prefix + '/bill/eticketnum/listEticketNum',
            checkbox: true,
            pagination: true,
            fitColumns: false,
            striped: true,
            singleSelect: false,
            loadMsg: "正在努力加载数据，请稍后...",
            queryParams: {},
            columns: [[
                {field: 'ck', checkbox: true},
                {title: '缴款书号', field: 'billnum', width: 160},
                {title: '单位名称', field: 'agencyname', width: 160},
                {title: '缴款人', field: 'payer', width: 100},
                {title: '缴款人账号', field: 'payeraccount'},
                {title: '缴款人开户行', field: 'payerbank'},
                {title: '金额', field: 'amt', width: 100},
                {title: '收款时间', field: 'paybankdt', width: 140},
                {title: '收款账号', field: 'payeeaccount', width: 150},
                {title: '收款户名', field: 'payee', width: 150},
                {title: '收款账户开户行', field: 'payeebank', width: 150},
                {title: '收款网点', field: 'bankstation', width: 130},
                {title: '交易流水号', field: 'bankaffirm', width: 140},
                {title: '缴款方式', field: 'payway', width: 100, formatter: function (value, row, index) { return getPayWay(value); }},
            ]],
            toolbar: '#toolbar',
            onBeforeLoad: function (param) {
                // 首次打开时，不加载数据
                var firstLoad = $(this).attr("firstLoad");  
                if (firstLoad == "false" || typeof (firstLoad) == "undefined") {  
                    $(this).attr("firstLoad","true");  
                    return false;  
                }  
                return true;  
            },
            onLoadSuccess: function (data) {
                if (data.total == 0) {
                    $('#grid-main-data').find('.datagrid-body').html('<div style="text-align: center;font-size: 14px;padding: 20px 0;">查询无数据</div>');
                }
            }
        });
        $(window).resize(function () {
            $('#MainGrid').datagrid('resize');
        });
        // 查询的下拉框
        $('#bankid').combogrid({
            panelWidth:550,
            idField:'bankid',
            textField:'accountcode',
            data: _bankdata,
            columns:[[
                {field: 'ck', checkbox: true},
                {field:'cantonname',title:'区划',width:80},
                {field:'accountcode',title:'账号',width:160},
                {field:'bankname',title:'开户行名称',width:260}
            ]]
        });
        // 发送复核表格
        $('#SendMainGrid').datagrid({
            pagination: false,
            fitColumns:false,
            striped: true,
            singleSelect: false,
            loadMsg: "正在加载数据，请稍后...",
            columns:[[
                {title: '缴款书号', field: 'billnum', width: 160},
                {title: '单位名称', field: 'agencyname', width: 160},
                {title: '缴款人', field: 'payer', width: 100},
                {title: '缴款人账号', field: 'payeraccount'},
                {title: '缴款人开户行', field: 'payerbank'},
                {title: '金额', field: 'amt', width: 100},
                {title: '收款时间', field: 'paybankdt', width: 140},
                {title: '收款户名', field: 'payee', width: 150},
                {title: '收款银行开户行', field: 'payeebank', width: 150},
                {title: '收款银行账号', field: 'payeeaccount', width: 150},
                {title: '收款网点', field: 'bankstation', width: 130},
                {title: '交易流水号', field: 'bankaffirm', width: 140},
                {title: '缴款方式', field: 'payway', width: 100, formatter: function (value, row, index) { return getPayWay(value); }},
            ]]
        });
    });

    function searchInfo() {
        if ($('#bankid').val() == '') {
            $.messager.alert('提示', '请选择收款账户', 'info');
            return;
        }
        $('#MainGrid').datagrid('load', {
            bankid: $('#bankid').val(),
            paybankdt: $('#paybankdt').val(),
            bankaffirm: $('#bankaffirmfind').val(),
            billnum: $('#billnum').val()
        });
    }


    //----------------------- 发送弹窗
    function sendInfo(opt) {
        $('#usercode').textbox('setValue', '');
        $('#userpwd').textbox('setValue', '');
        $('#biaoshi').val(opt);
        var tit = (opt == 1) ? '发送' : '冲销';
        if (opt == 1) {
            $('#sendClean').text('确认发送');
        } else {
            $('#sendClean').text('确认冲销');
        }
        var row = $('#MainGrid').datagrid('getSelections');
        if (row.length == 0) {
            $.messager.alert('提示', '请选择要' + tit + '的数据', 'info');
            return;
        }
        $("#SendBox-add").removeClass('hide').dialog({
            title: '&nbsp;' + tit,
            iconCls: 'icon-send',
            width: 600,
            height: 500,
            modal: true,
            buttons: [{
                text: '取消',
                iconCls: 'icon-cancel',
                width: 80,
                plain: false,
                handler: function () {
                    $('#SendBox-add').dialog('close')
                }
            }]
        });

        // 发送确认数据
        $('#SendMainGrid').datagrid({
            data:row,
        });
    }


    //  ----------------确认发送
    function pageSendInfo() {
        var usercode = $('#usercode').val();
        var userpwd = $('#userpwd').val();
        if (usercode == null || usercode == '') {
            $.messager.alert('提示', '请输入用户编码', 'info');
            return;
        }
        if (userpwd == null || userpwd == '') {
            $.messager.alert('提示', '请输入用户密码', 'info');
            return;
        }

        var row = $('#SendMainGrid').datagrid('getData');
        var list = [];
        $.each(row.rows, function (index, value) {
            list.push(value.billid)
        });

        var opt = $('#biaoshi').val();
        var url = (opt == 1) ? '/bill/eticketnum/sendEticketNum' : '/bill/eticketnum/cleanEticketNum';

        $.messager.progress({
           title: '提示',
           msg: '数据处理中，请稍候……',
           text: ''
        });
        $.ajax({
            url: prefix + url,
            type: 'POST',
            data: {
                usercode: usercode,
                userpwd: userpwd,
                billids: list.toString()
            },
            dataType: 'json',
            success:function(data){
                $.messager.alert('提示', data.msg, 'info', function() {
                    if (data.success) {
                        $('#SendBox-add').dialog('close');
                        if (opt == 2) searchInfo();
                    }
                    $.messager.progress('close');
                });
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                $.messager.alert('提示', '提交失败', 'info');
                $.messager.progress('close');
            }
        });
    }
</script>
</body>
</html>
